Skip to content

Conversation

@Alexendoo
Copy link
Member

@Alexendoo Alexendoo commented Oct 29, 2025

Fixes #13007

deprecated_cfg_attr now also lints inner attributes since it can catch the crate level ones, the suggestion is now MaybeIncorrect as there were some existing cases where the suggestion isn't valid and this adds some new ones

deprecated_clippy_cfg_attr uses stripped_cfg_items in addition to a regular early pass as it will typically be in a cfg that evaluates to false

non_minimal_cfg can't use stripped_cfg_items here though since it only stores the part of the cfg that evaluated to false whereas the lint needs the wider context, this means the lint no longer fires on code that is cfgd out, which may or may not be expected

non_minimal_cfg now also lints cfg_attr conditions and lints both empty any() and all(), suggesting to replace them with true/false as long as the MSRV is 1.88 (rust-lang/rust#138632)

changelog: [non_minimal_cfg] now lints empty any() and conditions in #[cfg_attr]s

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 29, 2025

r? @y21

rustbot has assigned @y21.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@github-actions
Copy link

github-actions bot commented Oct 29, 2025

Lintcheck changes for b21c720

Lint Added Removed Changed
clippy::deprecated_clippy_cfg_attr 14 0 0

This comment will be updated if you push new changes

@Alexendoo Alexendoo force-pushed the remove-pre-expansion-pass branch from 825beb0 to 870725a Compare October 29, 2025 16:30
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be a general regression on all these lints with non_minimal_cfg taking the biggest hit. Anything within a stripped out item will not be linted, including other attributes on said item. At the minimum I would note this in the known problems of non_minimal_cfg.

In practice actually working properly with lint attributes is probably more important. When cfg's are used solely to add things (e.g. only using #[cfg(feature = ...)]) then running clippy in a way that enables everything will work just fine. Using them for mutually exclusive paths (e.g. target based) will be a problem, especially if it's for small things like setting constant values. When the mutually exclusive parts are large chunks of code clippy would need to be run once for each path to lint them properly anyways.

View changes since this review

Comment on lines 163 to 164
/// `cfg_attr` is valid in some places that `rustfmt::skip` is not, e.g. outer attributes on
/// blocks and inner attributes on inline modules.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we easily not lint here by linting from all the other check_* functions instead of check_attributes.

The inner attribute could technically be moved to an outer attribute, but just not linting would be fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they were valid in fewer places than I thought. I think I have all the outer ones but may have missed something

I reverted the inner attribute change since a top level #![rustfmt::skip] isn't valid, I had just assumed it was based on the comment in the test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing check_arm, check_trait_item, check_impl_item and check_variant.

The attribute also works on fields and foreign items, but there's no corresponding check function.

@Alexendoo Alexendoo force-pushed the remove-pre-expansion-pass branch 4 times, most recently from a17040f to ac2220f Compare November 2, 2025 15:30
@Alexendoo Alexendoo force-pushed the remove-pre-expansion-pass branch from ac2220f to b21c720 Compare November 2, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

non_minimal_cfg suppression sometimes not effective

4 participants